﻿namespace WebPacker.Tool.Tests.EqualityComparers
{
	using System.Collections.Generic;
	using NUnit.Framework;
	using WebPacker.Configuration;

	public class PackInfoEqualityComparer : IEqualityComparer<PackInfo>
	{
		public bool Equals(PackInfo x, PackInfo y)
		{
			if (x == null || y == null)
			{
				return false;
			}

			if (x.Name != y.Name)
			{
				return false;
			}

			Assert.AreEqual(x.BasePath, y.BasePath);
			Assert.AreEqual(x.FilterName, y.FilterName);
			Assert.AreEqual(x.Monitoring, y.Monitoring);
			Assert.AreEqual(x.PackType, y.PackType);
			Assert.AreEqual(x.Version, y.Version);
			Assert.AreEqual(x.VersionGeneratorName, y.VersionGeneratorName);

			if (x.Resources != null)
			{
				Assert.IsNotNull(y.Resources);
				Assert.AreEqual(x.Resources.Length, y.Resources.Length);

				for (var i = 0; i < x.Resources.Length; i++)
				{
					Assert.AreEqual(x.Resources[i].Name, y.Resources[i].Name);
					Assert.AreEqual(x.Resources[i].Encoding, y.Resources[i].Encoding);
				}
			}
			else
			{
				Assert.IsNull(y.Resources);
			}

			return true;
		}

		public int GetHashCode(PackInfo obj)
		{
			return obj.GetHashCode();
		}
	}
}
